package com.egao.go.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.go.entity.DutchUser;
import com.egao.go.service.DutchUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 报名人
 * @author : Doman
 * @date : 2020-09-20 17:25:43
 * @version ：1.0
 */

@Api(tags = "报名人")
@RestController
@RequestMapping("/api/go/dutchUser")
public class DutchUserController extends BaseController {

	@Autowired
	private DutchUserService dutchUserService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('go:dutchUser:list')")
    @ApiPageParam
    @PostMapping("/page")
    public JsonResult page(PageResult2<T> page, DutchUser dutchUser) throws Exception{
        return dutchUserService.list(page, dutchUser, getLoginUser());
    }

    /**
     * 查询全部报名人
     */
    @PreAuthorize("hasAuthority('go:dutchUser:list')")
    @PostMapping("/list")
    public JsonResult list(DutchUser dutchUser){
        return dutchUserService.list(dutchUser, getLoginUser());
    }

    /**
     * 根据id查询报名人
     */
    @PreAuthorize("hasAuthority('go:dutchUser:list')")
    @PostMapping("/get")
    public JsonResult get(DutchUser dutchUser) {
        return dutchUserService.getById(dutchUser);
		// 使用关联查询
        //PageParam<dutchUser> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<dutchUser> records = dutchUserService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加报名人
     */
    @PreAuthorize("hasAuthority('go:dutchUser:save')")
    @OperLog(value = "报名人", desc = "添加", param = false, result = true)
    @ApiOperation("添加报名人")
    @PostMapping("/save")
    public JsonResult save(Model model, DutchUser dutchUser) {
        return dutchUserService.save(dutchUser, getLoginUser());
    }

    /**
     * 修改报名人
     */

    @PreAuthorize("hasAuthority('go:dutchUser:update')")
    @OperLog(value = "报名人", desc = "修改", param = false, result = true)
    @ApiOperation("修改报名人")
    @PostMapping("/update")
    public JsonResult update(Model model, DutchUser dutchUser) {
        return dutchUserService.update(dutchUser, getLoginUser());
    }

    /**
     * 删除报名人
     */
    @PreAuthorize("hasAuthority('go:dutchUser:remove')")
    @OperLog(value = "报名人", desc = "删除", result = true)
    @ApiOperation("删除报名人")
    @PostMapping("/remove")
    public JsonResult remove(DutchUser dutchUser ) {
        return dutchUserService.remove(dutchUser, getLoginUser());
    }

    /**
     * 批量添加报名人
     */
    /**@RequiresPermissions("go:dutchUser:save")
    @OperLog(value = "报名人", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<DutchUser> list) {
        if (dutchUserService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改报名人
     */
    /**@RequiresPermissions("go:dutchUser:update")
    @OperLog(value = "报名人", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<DutchUser> batchParam) {
        if (batchParam.update(dutchUserService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除报名人
     */
    /**@RequiresPermissions("go:dutchUser:remove")
    @OperLog(value = "报名人", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (dutchUserService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
